/**
 * Selling Partner API for FBA Inbound Eligibilty
 * With the FBA Inbound Eligibility API, you can build applications that let sellers get eligibility previews for items before shipping them to Amazon's fulfillment centers. With this API you can find out if an item is eligible for inbound shipment to Amazon's fulfillment centers in a specific marketplace. You can also find out if an item is eligible for using the manufacturer barcode for FBA inventory tracking. Sellers can use this information to inform their decisions about which items to ship Amazon's fulfillment centers.
 *
 * The version of the OpenAPI document: v1
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 *
 */

import { ApiClient } from '../ApiClient.js'
import { GetItemEligibilityPreviewResponse } from '../model/GetItemEligibilityPreviewResponse.js'
import { SuperagentRateLimiter } from '../../../helper/SuperagentRateLimiter.mjs'
import { DefaultRateLimitFetcher } from '../../../helper/DefaultRateLimitFetcher.mjs'

/**
* FbaInbound service.
* @module fbaeligibility_v1/api/FbaInboundApi
* @version v1
*/
export class FbaInboundApi {
  // Private member stores the default rate limiters
  #defaultRateLimiterMap

  /**
    * Constructs a new FbaInboundApi.
    * @alias module:fbaeligibility_v1/api/FbaInboundApi
    * @class
    * @param {ApiClient} [apiClient] Optional API client implementation to use,
    * default to {@link ApiClient#instance} if unspecified.
    */
  constructor (apiClient) {
    this.apiClient = apiClient || ApiClient.instance
    this.initializeDefaultRateLimiterMap()
  }

  /**
     * Initialize rate limiters for API operations
     */
  initializeDefaultRateLimiterMap () {
    this.#defaultRateLimiterMap = new Map()
    const defaultRateLimitFetcher = new DefaultRateLimitFetcher()
    const operations = [
      'FbaInboundApi-getItemEligibilityPreview'
    ]

    for (const operation of operations) {
      const config = defaultRateLimitFetcher.getLimit(operation)
      this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config))
    }
  }

  /**
     * Get rate limiter for a specific operation
     * @param {String} operation name
     */
  getRateLimiter (operation) {
    return this.#defaultRateLimiterMap.get(operation)
  }

  /**
     * This operation gets an eligibility preview for an item that you specify. You can specify the type of eligibility preview that you want (INBOUND or COMMINGLING). For INBOUND previews, you can specify the marketplace in which you want to determine the item&#39;s eligibility.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 1 |  The &#x60;x-amzn-RateLimit-Limit&#x60; response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     * @param {String} asin The ASIN of the item for which you want an eligibility preview.
     * @param {String} program The program that you want to check eligibility against.
     * @param {Object} opts Optional parameters
     * @param {[String]} opts.marketplaceIds The identifier for the marketplace in which you want to determine eligibility. Required only when program&#x3D;INBOUND.
     * @return {Promise<GetItemEligibilityPreviewResponse>}
     */
  getItemEligibilityPreviewWithHttpInfo (asin, program, opts) {
    opts = opts || {}
    const postBody = null

    // verify the required parameter 'asin' is set
    if (asin === undefined || asin === null) {
      throw new Error("Missing the required parameter 'asin' when calling getItemEligibilityPreview")
    }

    // verify the required parameter 'program' is set
    if (program === undefined || program === null) {
      throw new Error("Missing the required parameter 'program' when calling getItemEligibilityPreview")
    }

    const pathParams = {
    }
    const queryParams = {
      marketplaceIds: this.apiClient.buildCollectionParam(opts.marketplaceIds, 'csv'),
      asin,
      program
    }
    const headerParams = {
    }
    const formParams = {
    }

    const contentTypes = []
    const accepts = ['application/json', 'ItemEligibilityPreview']
    const returnType = GetItemEligibilityPreviewResponse

    return this.apiClient.callApi('FbaInboundApi-getItemEligibilityPreview',
      '/fba/inbound/v1/eligibility/itemPreview', 'GET',
      pathParams, queryParams, headerParams, formParams, postBody,
      contentTypes, accepts, returnType, this.getRateLimiter('FbaInboundApi-getItemEligibilityPreview')
    )
  }

  /**
     * This operation gets an eligibility preview for an item that you specify. You can specify the type of eligibility preview that you want (INBOUND or COMMINGLING). For INBOUND previews, you can specify the marketplace in which you want to determine the item&#39;s eligibility.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 1 |  The &#x60;x-amzn-RateLimit-Limit&#x60; response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     * @param {String} asin The ASIN of the item for which you want an eligibility preview.
     * @param {String} program The program that you want to check eligibility against.
     * @param {Object} opts Optional parameters
     * @param {[String]} opts.marketplaceIds The identifier for the marketplace in which you want to determine eligibility. Required only when program&#x3D;INBOUND.
     * @return {Promise<GetItemEligibilityPreviewResponse>}
     */
  getItemEligibilityPreview (asin, program, opts) {
    return this.getItemEligibilityPreviewWithHttpInfo(asin, program, opts)
      .then(function (response_and_data) {
        return response_and_data.data
      })
  }
}
